/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facturacion;
import Examen.Controller.Conexion;
import java.awt.Image;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import java.util.Calendar;
import javax.swing.JOptionPane;

/**
 *
 * @author CEBALLOS
 */
public class f_Cuentas extends javax.swing.JFrame {

    
    static int j=0,w=0,jj=0,VSubtotal=0,VIva=0,VDescu=0,VMontoIn=0,VMontoOut=0;
    static float invT=0,invIn=0,invOut=0;
    Conexion con,query;
    ResultSet rs;
    ResultSet rs2;
    static String inv[]=new String[50000];
    static String inv2[]=new String[50000];
    static String inv3[]=new String[50000];
    
    Calendar fecha = Calendar.getInstance();  //  @jve:decl-index=0:
    /**
     * Creates new form FRM
     */
    public f_Cuentas() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TxtFecha = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        TxtCredito = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        TxtContado = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable4 = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        TxtEntradas = new javax.swing.JTextField();
        TxtSalidas = new javax.swing.JTextField();
        TxtTotalCaja = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        TxtLetras = new javax.swing.JLabel();
        TxtSalidasLetras = new javax.swing.JLabel();
        TxtEntradasLetras = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        BtnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CIERRE DE CAJA");
        setIconImage(getIconImage());
        setResizable(false);

        TxtFecha.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                TxtFechaFocusGained(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("VENTAS A CREDITO");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NUM_FAC", "FECHA", "ID_CLI", "ID_VEN", "FOR_PAG", "DESCU", "SUB_GEN", "TOT_DES", "TOT_IVA", "OBSERVACION", "ANULADA", "PAGO_INI"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        TxtCredito.setEditable(false);
        TxtCredito.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Total Creditos");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(TxtCredito, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtCredito, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)))
        );

        jButton1.setText("Calcular");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setText("VENTAS A CONTADO");

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7", "Title 8", "Title 9", "Title 10"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        TxtContado.setEditable(false);
        TxtContado.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel4.setText("Total Efectivo en Ventas de Contado");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(TxtContado, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(4, 4, 4)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TxtContado, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jLabel4)))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setForeground(new java.awt.Color(51, 204, 0));
        jLabel5.setText("ENTRADAS DE DINERO A CAJA");

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable3);

        jTable4.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane4.setViewportView(jTable4);

        jLabel6.setForeground(new java.awt.Color(204, 51, 0));
        jLabel6.setText("SALIDAS DE DINERO EN CAJA");

        TxtEntradas.setEditable(false);
        TxtEntradas.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        TxtSalidas.setEditable(false);
        TxtSalidas.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        TxtTotalCaja.setEditable(false);
        TxtTotalCaja.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(51, 255, 51));
        jLabel7.setText("Entradas");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(0, 0, 204));
        jLabel8.setText("Total Caja");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(204, 51, 0));
        jLabel9.setText("Salidas");

        TxtLetras.setForeground(new java.awt.Color(0, 0, 204));

        TxtSalidasLetras.setForeground(new java.awt.Color(204, 51, 0));

        TxtEntradasLetras.setForeground(new java.awt.Color(51, 255, 51));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(TxtEntradas, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(TxtEntradasLetras, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(TxtSalidas, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(TxtTotalCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(TxtSalidasLetras, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TxtLetras, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(TxtSalidasLetras, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(TxtEntradas, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(TxtEntradasLetras, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(TxtSalidas, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9))
                                .addGap(9, 9, 9))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(jLabel6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TxtTotalCaja, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(TxtLetras, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel10.setText("FECHA");

        BtnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/SALIR.JPG"))); // NOI18N
        BtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 587, Short.MAX_VALUE)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(TxtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(48, 48, 48)
                        .addComponent(BtnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TxtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10))
                    .addComponent(BtnSalir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
  
    @Override
    public Image getIconImage(){
    
        Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("IMAGENES/icon.png"));
    return retValue;
    }
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
              CalculosaCredito();
              CalculosaContado();
              CalculosEntradas();
              CalculosSalidas();
              CalculosTotalCaja();
    }//GEN-LAST:event_jButton1ActionPerformed

    public void CalculosTotalCaja(){
        
                
        double Contado=Double.parseDouble(TxtContado.getText());
        double Entradas=Double.parseDouble(TxtEntradas.getText());
        double Salidas=Double.parseDouble(TxtSalidas.getText());
        
        double Total = Contado+Entradas-Salidas;
       
        TxtTotalCaja.setText(""+Total);
       
        Numero_Letra NumLetra = new Numero_Letra();
       
        String Totales;
        Totales = TxtTotalCaja.getText();
        
        String SalidasLetras;
        SalidasLetras = TxtSalidas.getText();
        
        String EntradasLetras;
        EntradasLetras = TxtEntradas.getText();
        
        TxtLetras.setText(""  + NumLetra.Convertir(Totales,true)); 
        TxtSalidasLetras.setText(""  + NumLetra.Convertir(SalidasLetras,true));
        TxtEntradasLetras.setText(""  + NumLetra.Convertir(EntradasLetras,true));
        
        //System.out.println(""  + NumLetra.Convertir(numero,true));
       
       
      
    
    }
    
    private void TxtFechaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_TxtFechaFocusGained
        // TODO add your handling code here:
        limpiar();
        cargarfecha();
       // CargarTabla();
    }//GEN-LAST:event_TxtFechaFocusGained

    private void BtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnSalirActionPerformed
        // TODO add your handling code here:
        int resp=JOptionPane.showConfirmDialog(null,"Desea salir del formulario?","Salir del formulario",0);
        if(resp==0)
        {dispose();}
    }//GEN-LAST:event_BtnSalirActionPerformed

    public void limpiar(){
	//TxtNumero.setText("");
	//TxtCliente.setText("");
	TxtFecha.setText("");
	//CboVendedor.setSelectedIndex(-1);
       // JOptionPane.showMessageDialog(null,"LIMPIAR OK","",2);
    }  
     private void cargarfecha(){
  //  JOptionPane.showMessageDialog(null,"CARGAR FECHA OK","",2);
	String fechactual="";
	String dia=String.valueOf(fecha.get(fecha.DAY_OF_MONTH));
	if (dia.length()==1)
	   {dia="0"+dia;}
	String mes=String.valueOf(fecha.get(fecha.MONTH)+1);
	if (mes.length()==1)
	   {mes="0"+mes;}
	String año=String.valueOf(fecha.get(fecha.YEAR));
	fechactual=dia+"/"+mes+"/"+año;
        TxtFecha.setText(fechactual);
}
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(f_salidas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new f_salidas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnSalir;
    private javax.swing.JTextField TxtContado;
    private javax.swing.JTextField TxtCredito;
    private javax.swing.JTextField TxtEntradas;
    private javax.swing.JLabel TxtEntradasLetras;
    private javax.swing.JTextField TxtFecha;
    private javax.swing.JLabel TxtLetras;
    private javax.swing.JTextField TxtSalidas;
    private javax.swing.JLabel TxtSalidasLetras;
    private javax.swing.JTextField TxtTotalCaja;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTable jTable4;
    // End of variables declaration//GEN-END:variables
    
    
    
    
    
    public void CalculosaCredito(){
        
           // TODO add your handling code here:
        
        //jj=0;   
    try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) {
                    Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
                }
        
         String sql ="SELECT * FROM facv_cab where (ANULADA)=0 AND (FOR_PAG) = 'CREDITO' AND DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
       rs = con.Consulta(sql);
            
              
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTable1.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
          while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          
          inv[VSubtotal] = rs.getString(7);
          inv2[VIva] = rs.getString(9);
          inv3[VDescu] = rs.getString(8);
         
          
          // String ka1 = rs.getString(4);
         // int ka = Integer.parseInt(ka1);
           
          Float auxo = Float.parseFloat(inv[VSubtotal]);
          Float auxo2 = Float.parseFloat(inv2[VIva]);
          Float auxo3 = Float.parseFloat(inv3[VDescu]);
           
          // auxo = auxo * ka;
            
          invT = invT + auxo +auxo2- auxo3;                   
           
            VSubtotal++;
            //jj++;
         
            for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
            }
          buscar.addRow(fila);
          }

        
        TxtCredito.setText(""+invT);
        //jLabel1.setText(""+invT);
        
        invT = 0;
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
        }
 
            
    
    
    
    }
    
    
    
    public void CalculosaContado(){
        
           // TODO add your handling code here:
        
        //jj=0;   
    try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) {
                    Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
                }
        
        //String id6= jTID.getText();
       /* String sql ="select facv_cab.num_facv,DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y') as fecha,concat(clientes.ape_cli,' ',clientes.nom_cli) as elcliente,concat(vendedores.ape_ven,' ',vendedores.nom_ven) as elvendedor,"+
                                    "(facv_cab.sub_gen-facv_cab.tot_des+facv_cab.tot_iva) as total,anulada from facv_cab inner join clientes on(facv_cab.id_cli=clientes.id_cli) inner join vendedores on(facv_cab.id_ven=vendedores.id_ven) "+
                                    "where DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
      */
      // OK consulta String sql ="SELECT * FROM facv_cab where (FOR_PAG) = 'CREDITO' AND DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
       //String sql = "SELECT * FROM facv_cab where (FOR_PAG) = 'CONTADO' order by num_facv";
       String sql ="SELECT * FROM facv_cab where (ANULADA)=0 AND (FOR_PAG) = 'CONTADO' AND DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
       rs = con.Consulta(sql);
            
              
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTable2.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
          while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          
          inv[VSubtotal] = rs.getString(7);
          inv2[VIva] = rs.getString(9);
          inv3[VDescu] = rs.getString(8);
         
          
          // String ka1 = rs.getString(4);
         // int ka = Integer.parseInt(ka1);
           
          Float auxo = Float.parseFloat(inv[VSubtotal]);
          Float auxo2 = Float.parseFloat(inv2[VIva]);
          Float auxo3 = Float.parseFloat(inv3[VDescu]);
           
          // auxo = auxo * ka;
            
          invT = invT + auxo +auxo2- auxo3;                   
           
            VSubtotal++;
            //jj++;
         
            for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
            }
          buscar.addRow(fila);
          }

        
        TxtContado.setText(""+invT);
        //jLabel1.setText(""+invT);
        
        invT = 0;
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
        }
 
            
    
    
    
    }


    public void CalculosEntradas(){
        
           // TODO add your handling code here:
        
        //jj=0;   
    try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) {
                    Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
                }
        
           String sql ="SELECT * FROM ENTRADAS where DATE_FORMAT(ENTRADAS.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by id_in";
       
        rs = con.Consulta(sql);
            
              
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTable4.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
          while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          
          inv[VMontoIn] = rs.getString(2);
           
            Float auxo = Float.parseFloat(inv[VMontoIn]);
             
            invIn = invIn + auxo ;//+auxo2- auxo3;                   
           
            VMontoIn++;
            jj++;
         
            for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
            }
          buscar.addRow(fila);
          }

        
         TxtEntradas.setText(""+invIn);
        //jLabel1.setText(""+invT);
        
          invIn = 0;
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
        }
 
            
    
    
    
    }
    public void CalculosSalidas(){
        
           // TODO add your handling code here:
        
        //jj=0;   
    try {
            // se comienza la conexion con la base de datos
        try {
                    con = new Conexion();


                } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) {
                    Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
                }
        
        //String id6= jTID.getText();
       /* String sql ="select facv_cab.num_facv,DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y') as fecha,concat(clientes.ape_cli,' ',clientes.nom_cli) as elcliente,concat(vendedores.ape_ven,' ',vendedores.nom_ven) as elvendedor,"+
                                    "(facv_cab.sub_gen-facv_cab.tot_des+facv_cab.tot_iva) as total,anulada from facv_cab inner join clientes on(facv_cab.id_cli=clientes.id_cli) inner join vendedores on(facv_cab.id_ven=vendedores.id_ven) "+
                                    "where DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
      */
      // OK consulta String sql ="SELECT * FROM facv_cab where (FOR_PAG) = 'CREDITO' AND DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
       //String sql = "SELECT * FROM facv_cab where (FOR_PAG) = 'CONTADO' order by num_facv";
       //String sql ="SELECT * FROM facv_cab where (ANULADA)=0 AND (FOR_PAG) = 'CONTADO' AND DATE_FORMAT(facv_cab.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by num_facv";
         String sql ="SELECT * FROM SALIDAS where DATE_FORMAT(SALIDAS.fecha,'%d/%m/%Y')= '"+ TxtFecha.getText() +"' order by id_out";
       
        rs = con.Consulta(sql);
            
              
         //Para establecer el modelo al JTable
 
        DefaultTableModel buscar = new DefaultTableModel(){
                        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }};
        this.jTable3.setModel(buscar);
        
        //Obteniendo la informacion de las columnas que estan siendo consultadas
         ResultSetMetaData rsMd = rs.getMetaData();
         //La cantidad de columnas que tiene la consulta
         int cantidadColumnas = rsMd.getColumnCount();
         //Establecer como cabezeras el nombre de las colimnas
         for (int i = 1; i <= cantidadColumnas; i++) {
          buscar.addColumn(rsMd.getColumnLabel(i));
         }
        
        
          while (rs.next()) {
          Object[] fila = new Object[cantidadColumnas];
  
          
          inv[VMontoOut] = rs.getString(2);
          //inv2[VIva] = rs.getString(9);
          //inv3[VDescu] = rs.getString(8);
         
          
          // String ka1 = rs.getString(4);
           //int ka = Integer.parseInt(ka1);
           
            Float auxo = Float.parseFloat(inv[VMontoOut]);
         // Float auxo2 = Float.parseFloat(inv2[VIva]);
         // Float auxo3 = Float.parseFloat(inv3[VDescu]);
           
          // auxo = auxo * ka;
            
            invOut = invOut + auxo ;//+auxo2- auxo3;                   
           
            VMontoOut++;
            jj++;
         
            for (int i = 0; i < cantidadColumnas; i++) {
             
            fila[i]=rs.getObject(i+1);
            }
          buscar.addRow(fila);
          }

        
         TxtSalidas.setText(""+invOut);
       
        
         invOut = 0; //permite que no se sumen los valores en cada consulta de manera redundante!!
 
 
                
                
                
                
                
                
        } catch (SQLException ex) {
            Logger.getLogger(f_salidas.class.getName()).log(Level.SEVERE, null, ex);
        }
 
            
    
    
    
    }
    
    
    
    


}
